package com.xbongbong.paas.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.crm.service.SearchCustomerService;
import com.xbongbong.paas.help.menu.InitMenuHelp;
import com.xbongbong.paas.service.SearchCustomerDataService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.thread.TransmittableThreadLocalUtil;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.menu.pojo.dto.MenuInitDTO;
import com.xbongbong.pro.menu.pojo.vo.MenuInitVO;
import com.xbongbong.pro.searchcustomer.pojo.dto.SearchCustomerAdminDTO;
import com.xbongbong.pro.searchcustomer.pojo.dto.SearchCustomerCallbackDTO;
import com.xbongbong.pro.searchcustomer.pojo.dto.SearchCustomerDTO;
import com.xbongbong.pro.searchcustomer.pojo.dto.SearchCustomerDataDTO;
import com.xbongbong.pro.searchcustomer.pojo.dto.SearchCustomerStaffDTO;
import com.xbongbong.pro.searchcustomer.pojo.dto.SearchCustomerTemplateDTO;
import com.xbongbong.pro.searchcustomer.pojo.dto.SearchCustomerUserDTO;
import com.xbongbong.pro.searchcustomer.pojo.dto.SearchEnterpriseDTO;
import com.xbongbong.pro.searchcustomer.pojo.dto.TargetDTO;
import com.xbongbong.pro.searchcustomer.pojo.vo.JumpClueDetailVO;
import com.xbongbong.pro.searchcustomer.pojo.vo.SearchCustomerDataVO;
import com.xbongbong.pro.searchcustomer.pojo.vo.SearchCustomerMealVO;
import com.xbongbong.pro.searchcustomer.pojo.vo.SearchCustomerMsgVO;
import com.xbongbong.pro.searchcustomer.pojo.vo.SearchCustomerTemplateVO;
import com.xbongbong.pro.searchcustomer.pojo.vo.SearchCustomerUserListVO;
import com.xbongbong.pro.searchcustomer.pojo.vo.SearchCustomerVO;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Objects;

/**
 * @Author shian
 * @des: 搜客管理
 * @create 2019-07-25 14:00
 */
@RestController
@RequestMapping(value = XbbProConstant.API_ROOT_PREFIX + "/searchCustomer")
public class SearchCustomerController {

    @Resource
    private InitMenuHelp initMenuHelp;
    @Resource
    private SearchCustomerService searchCustomerService;
    @Resource
    private SearchCustomerDataService searchCustomerDataService;

    /**
     * 初始化搜客菜单
     * @param menuInitDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-07-31
     */
    @RequestMapping(value = "/initMenu", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String initSearchCustomer(@RequestBody @Valid MenuInitDTO menuInitDTO, BindingResult br){
        XbbResponse<MenuInitVO> response = new XbbResponse<>();
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                if (!Objects.equals(menuInitDTO.getAlias(), XbbRefTypeEnum.SEARCH_CUSTOMER.getAlias())) {
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100028);
                }
                initMenuHelp.menuInit(menuInitDTO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 搜客应用开户注册接口
     * @param searchCustomerDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-02
     */
    @RequestMapping(value = "/register", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String register(@RequestBody @Valid SearchCustomerDTO searchCustomerDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        SearchCustomerVO searchCustomerVO;
        JSONObject jsonObject;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                jsonObject = searchCustomerService.sendRegister(searchCustomerDTO);
                searchCustomerVO = JSONObject.toJavaObject(jsonObject ,SearchCustomerVO.class);
                response = new XbbResponse<>(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }
    /**
     *  搜客应用开户注册回调接口
     * @param searchCustomerCallbackDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-07-31
     */
    @RequestMapping(value = "/registerCallback", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String registerCallback(@RequestBody @Valid SearchCustomerCallbackDTO searchCustomerCallbackDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        SearchCustomerVO searchCustomerVO;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                searchCustomerVO = searchCustomerService.getCustomerInfo(searchCustomerCallbackDTO);
                return JSONObject.toJSONString(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 登录搜客应用
     * @param searchCustomerDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-02
     */
    @RequestMapping(value = "/signIn", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String loginSearchCustomer(@RequestBody @Valid SearchCustomerDTO searchCustomerDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        SearchCustomerVO searchCustomerVO;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                searchCustomerVO = searchCustomerService.loginSearchCustomer(searchCustomerDTO);
                response = new XbbResponse<>(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 绑定用户
     * @param searchCustomerDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-05
     */
    @RequestMapping(value = "/bind", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String bindUser(@RequestBody @Valid SearchCustomerDTO searchCustomerDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        SearchCustomerVO searchCustomerVO ;
        JSONObject jsonObject;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                jsonObject = searchCustomerService.bind(searchCustomerDTO);
                searchCustomerVO = JSONObject.toJavaObject(jsonObject ,SearchCustomerVO.class);
                response = new XbbResponse<>(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 解绑用户
     * @param searchCustomerDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-05
     */
    @RequestMapping(value = "/unbind", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String unbindUser(@RequestBody @Valid SearchCustomerDTO searchCustomerDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        SearchCustomerVO searchCustomerVO = new SearchCustomerVO();
        JSONObject jsonObject = new JSONObject();
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                jsonObject = searchCustomerService.unbind(searchCustomerDTO);
                searchCustomerVO = JSONObject.toJavaObject(jsonObject ,SearchCustomerVO.class);
                response = new XbbResponse<>(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }
    /**
     * 升级或续费 (只有id为主账户的角色才可以升级/续期)
     * @param searchCustomerDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-05
     */
    @RequestMapping(value = "/meal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String mealManage(@RequestBody @Valid SearchCustomerDTO searchCustomerDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        SearchCustomerVO searchCustomerVO;
        JSONObject jsonObject;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                jsonObject = searchCustomerService.meal(searchCustomerDTO);
                searchCustomerVO = JSONObject.toJavaObject(jsonObject ,SearchCustomerVO.class);
                return JSONObject.toJSONString(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 查询（主/子）账号信息
     * @param searchCustomerDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-05
     */
    @RequestMapping(value = "/info", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String userMessage(@RequestBody @Valid SearchCustomerDTO searchCustomerDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        SearchCustomerVO searchCustomerVO;
        JSONObject jsonObject;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                jsonObject = searchCustomerService.info(searchCustomerDTO);
                searchCustomerVO = JSONObject.toJavaObject(jsonObject ,SearchCustomerVO.class);
                response = new XbbResponse<>(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 查看主/子账户套餐信息
     * @param searchCustomerDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-09-17
     */
    @RequestMapping(value = "/user/package", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String userPackage(@RequestBody @Valid SearchCustomerDTO searchCustomerDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        SearchCustomerVO searchCustomerVO;
        JSONObject jsonObject;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                jsonObject = searchCustomerService.userPackage(searchCustomerDTO);
                searchCustomerVO = JSONObject.toJavaObject(jsonObject ,SearchCustomerVO.class);
                response = new XbbResponse<>(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }


    /**
     * 禁用或者启用用户使用搜客
     * @param searchCustomerDTO
     * @param br
     * @return java.lang.String 
     * @author 石安 
     * @date 2019-09-16 
     */
    @RequestMapping(value = "/user/enable", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String enable(@RequestBody @Valid SearchCustomerDTO searchCustomerDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        SearchCustomerVO searchCustomerVO;
        JSONObject jsonObject;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                jsonObject = searchCustomerService.enable(searchCustomerDTO);
                searchCustomerVO = JSONObject.toJavaObject(jsonObject ,SearchCustomerVO.class);
                response = new XbbResponse<>(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 注销搜客用户
     * @param searchCustomerDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-27
     */
    @RequestMapping(value = "/user/disuser", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String disuser(@RequestBody @Valid SearchCustomerDTO searchCustomerDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        SearchCustomerVO searchCustomerVO;
        JSONObject jsonObject;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                jsonObject = searchCustomerService.disuser(searchCustomerDTO);
                searchCustomerVO = JSONObject.toJavaObject(jsonObject ,SearchCustomerVO.class);
                response = new XbbResponse<>(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     *  搜客应用通知回调接口
     *  此回调在我的线索板块手动触发
     * @param searchCustomerCallbackDTO
     * @param targetDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-05
     */
    @RequestMapping(value = "/notifyCallback", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String notifyCallback(@RequestBody @Valid SearchCustomerCallbackDTO searchCustomerCallbackDTO, @Valid TargetDTO targetDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        SearchCustomerVO searchCustomerVO;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                searchCustomerVO = searchCustomerService.notifyInfo(searchCustomerCallbackDTO, targetDTO);
                return JSONObject.toJSONString(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 前端获取搜客转过来的数据（搜客转客户->后端接收数据->前端拿数据）
     * @param searchCustomerDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-20
     */
    @RequestMapping(value = "/notice/value", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String notice(@RequestBody @Valid SearchCustomerDTO searchCustomerDTO, BindingResult br){
        XbbResponse<SearchCustomerDataVO> response;
        SearchCustomerDataVO searchCustomerDataVO;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                searchCustomerDataVO = searchCustomerService.notice(searchCustomerDTO);
                response = new XbbResponse<>(searchCustomerDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);

    }

    /**
     * 获取模糊匹配模板
     * @param searchCustomerTemplateDTO
     * @param br
     * @return java.lang.String 
     * @author 石安 
     * @date 2019-08-05 
     */
    @RequestMapping(value = "/template", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String useTemplate(@RequestBody @Valid SearchCustomerTemplateDTO searchCustomerTemplateDTO, BindingResult br){
        XbbResponse<SearchCustomerTemplateVO> response;
        SearchCustomerTemplateVO searchCustomerTemplateVO = new SearchCustomerTemplateVO();
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                searchCustomerTemplateVO = searchCustomerService.useTemplate(searchCustomerTemplateDTO);
                response = new XbbResponse<>(searchCustomerTemplateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     *  保存模糊匹配模板
     * @param searchCustomerTemplateDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-07
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String saveTemplate(@RequestBody @Valid SearchCustomerTemplateDTO searchCustomerTemplateDTO, BindingResult br){
        XbbResponse<SearchCustomerTemplateVO> response;
        SearchCustomerTemplateVO searchCustomerTemplateVO = new SearchCustomerTemplateVO();
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                searchCustomerTemplateVO = searchCustomerService.saveTemplate(searchCustomerTemplateDTO);
                response = new XbbResponse<>(searchCustomerTemplateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取员工的搜客权限管理
     * @param searchCustomerUserDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-07
     */
    @RequestMapping(value = "/dep/userList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getDepUserList(@RequestBody @Valid SearchCustomerUserDTO searchCustomerUserDTO, BindingResult br) {
        SearchCustomerUserListVO searchCustomerUserListVO;
        XbbResponse<SearchCustomerUserListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                searchCustomerUserListVO = searchCustomerService.getDepUserList(searchCustomerUserDTO);
                response = new XbbResponse<>(searchCustomerUserListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 设置搜客管理员
     * @param searchCustomerAdminDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-08
     */
    @RequestMapping(value = "/set/admin", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateAdmin(@RequestBody @Valid SearchCustomerAdminDTO searchCustomerAdminDTO, BindingResult br) {
        SearchCustomerMsgVO searchCustomerMsgVO;
        XbbResponse<SearchCustomerMsgVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                searchCustomerMsgVO = searchCustomerService.updateAdmin(searchCustomerAdminDTO);
                response = new XbbResponse<>(searchCustomerMsgVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 设置搜客员工
     * @param searchCustomerStaffDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-08
     */
    @RequestMapping(value = "/set/staff", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateStaff(@RequestBody @Valid SearchCustomerStaffDTO searchCustomerStaffDTO, BindingResult br) {
        SearchCustomerMsgVO searchCustomerMsgVO;
        XbbResponse<SearchCustomerMsgVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                searchCustomerMsgVO = searchCustomerService.updateStaff(searchCustomerStaffDTO);
                response = new XbbResponse<>(searchCustomerMsgVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }
    /**
     *  搜客的套餐信息
     * @param searchCustomerUserDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-07
     */
    @RequestMapping(value = "/company/meal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getMeal(@RequestBody @Valid SearchCustomerUserDTO searchCustomerUserDTO, BindingResult br){
        XbbResponse<SearchCustomerMealVO> response;
        SearchCustomerMealVO searchCustomerMealVO;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                searchCustomerMealVO = searchCustomerService.getCompanyMeal(searchCustomerUserDTO);
                response = new XbbResponse<>(searchCustomerMealVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 搜客转客户或转公海
     * @param searchCustomerDataDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-13
     */
    @RequestMapping(value = "/transfer/customer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String transferCustomer(@RequestBody @Valid SearchCustomerDataDTO searchCustomerDataDTO, BindingResult br){
        XbbResponse<SearchCustomerMsgVO> response;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(searchCustomerDataDTO.getSaasMark(), searchCustomerDataDTO.getBusinessType(), searchCustomerDataDTO.getMenuId(), searchCustomerDataDTO.getDistributorMark());
                SearchCustomerMsgVO searchCustomerMsgVO = searchCustomerDataService.addBatch(searchCustomerDataDTO);
                response = new XbbResponse<>(searchCustomerMsgVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取转客户或公海的任务状态
     * @param searchCustomerDataDTO
     * @param br 
     * @return java.lang.String
     * @author 石安 
     * @date 2019-09-09 
     */
    @RequestMapping(value = "/transfer/status", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getTransferStatus(@RequestBody @Valid SearchCustomerDataDTO searchCustomerDataDTO, BindingResult br){
        XbbResponse<SearchCustomerMsgVO> response;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                SearchCustomerMsgVO searchCustomerMsgVO = searchCustomerDataService.getStatus(searchCustomerDataDTO);
                response = new XbbResponse<>(searchCustomerMsgVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }


    /**
     * 企业模糊查询
     * @param searchEnterpriseDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-15
     */
    @RequestMapping(value = "/search/enterprise", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String search(@RequestBody @Valid SearchEnterpriseDTO searchEnterpriseDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                SearchCustomerVO searchCustomerVO = searchCustomerService.search(searchEnterpriseDTO);
                response = new XbbResponse<>(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取企业基本信息
     * @param searchEnterpriseDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-08-15
     */
    @RequestMapping(value = "/enterprise/baseInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String baseInfo(@RequestBody @Valid SearchEnterpriseDTO searchEnterpriseDTO, BindingResult br){
        XbbResponse<SearchCustomerVO> response;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                SearchCustomerVO searchCustomerVO = searchCustomerService.baseInfo(searchEnterpriseDTO);
                response = new XbbResponse<>(searchCustomerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 客户详情中跳转栗子详情
     * @param searchEnterpriseDTO
     * @param br
     * @return java.lang.String
     * @author 石安
     * @date 2019-11-25
     */
    @RequestMapping(value = "/clue/detail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getClueDetail(@RequestBody @Valid SearchEnterpriseDTO searchEnterpriseDTO, BindingResult br){
        XbbResponse<JumpClueDetailVO> response;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                JumpClueDetailVO jumpClueDetailVO = searchCustomerService.getClueDetail(searchEnterpriseDTO);
                response = new XbbResponse<>(jumpClueDetailVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }
}
